<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'add.jsp' starting page</title>
    
   	<link href="<%=request.getContextPath() %>/css/add.css" type="text/css" rel="stylesheet">
	  <script type="text/javascript" src="/js/jquery-1.8.3.min.js"></script>
	  <script type="text/javascript">
		  $(function (){

			  $("[name=uname]").blur(function (){

				  //获取用户名
				  let value=$("[name=uname]").val();

				  //发出ajax请求对用户名进行验证
				  $.ajax({
					  url:"/AdminUser/checkName",
					  data:{"uname":value},
					  type:"post",
					  dataType:"json",
					  success:function (data){
						  if (data){//data==true 用户名存在
								$("#mySpan").html("<img src='/img/no.png'/>用户名已经存在");
						  }else {//用户名不存在
							  	$("#mySpan").html("<img src='/img/ok.png'/>");
						  }
					  }
				  });
			  });
		  });
	  </script>
	
  </head>
  
  <body>
  	<div id="up">
	   <ul>
	    	<li><span><a href="#">用户管理 </a>&gt; 添加用户 &gt;</span></li>
	   </ul>
	</div>
	<div id="down">
	    <form method="post" action="/AdminUser/addUser">
	   		<table width="1000px">
	   			<tr>
	   				<td>用户名称：</td>
	   				<td><input type="text" name="uname" class="in"/><span id="mySpan"></span></td>
	   			</tr>
	   			<tr>
	   				<td>用户密码：</td>
	   				<td><input type="text" name="upassword" class="in"/></td>
	   			</tr>
	   			<tr>
	   				<td>余额：</td>
	   				<td><input type="number" name="ucount" class="in"/></td>
	   			</tr>
				<tr>
					<td>邮箱：</td>
					<td><input type="text" name="uemil" class="in"/></td>
				</tr>


	   			<tr>
	   				<td>角色</td>
	   				<td>
	   					<select name="pid" class="in">
							<c:forEach items="${list}" var="power">
								<option value="${power.pid}">${power.pname}</option>
							</c:forEach>
	   					</select>
	   				</td>
	   			</tr>
	   			
	   			<tr>
	   				<td></td>
	   				<td>
	   					<input type="submit" value="提&nbsp;&nbsp;&nbsp;交" class="su">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	   					<input type="reset" value="清&nbsp;&nbsp;&nbsp;空" class="su">
	   				</td>
	   			</tr>
	   		</table>
	    </form>
    </div>
  </body>
</html>
